package com.obc.quantity;

//Understands a metric systems
public class Unit {

	private static final int INCHES_IN_FOOT = 12;
	private static final int GRAMS_IN_KILO = 1000;
	
	// slug example
	private final static Object DISTANCE = new Object();
	private static final Object WEIGHT = new Object();
	
	private final Object unitType; 
	private double numberOfBaseUnit = 1; 
	private final String name; 
	
	public String name(){
		return name;
	}
	
	static final Unit FOOT = new Unit(DISTANCE, INCHES_IN_FOOT, "feet");
	static final Unit INCH = new Unit(DISTANCE, "inches");

	static final Unit GRAM = new Unit(WEIGHT, "grams");
	static final Unit KILO = new Unit(WEIGHT, GRAMS_IN_KILO, "kilos");
	
	private Unit(Object unitType, String name) {
		this.unitType = unitType;
		this.name = name;
	}

	private Unit(Object unitType, double numberOfBaseUnit, String name) {
		this.unitType = unitType;
		this.numberOfBaseUnit = numberOfBaseUnit;
		this.name = name;
	}

	public double convertToBaseUnit(double value, Unit fromUnit) {
		return value*fromUnit.numberOfBaseUnit;
	}

	public boolean comparableWith(Unit other) {
		return unitType == other.unitType;
	}
	
	public static Unit baseUnitFor(Unit unit) {
		if (unit.unitType == DISTANCE) return INCH; 
		if (unit.unitType == WEIGHT) return GRAM; 
		throw new RuntimeException("Unavailable Unit Type!");
	}
	
}
